package com.base.core.utils;

import com.base.core.model.ApiRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常拦截
 * @author zhaojiulin
 * @date 2020/2/27 13:34
 */
@RestControllerAdvice
public class BaseExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(BaseExceptionHandler.class);

    @ExceptionHandler(BaseException.class)
    public ApiRes HandleBusinessException(BaseException ex){
        logger.error(ex.getMessage());
        return ApiRes.failed(ex.getMessage());
    }
}
